package validate

import (
	"github.com/go-playground/validator/v10"
	"go-project/dto/requrest"
	"go-project/models"
)

func ArticleCategoryNameValidate(field validator.FieldLevel) bool {
	articleCategoryModel := &models.ArticleCategory{}
	username := field.Field().String()
	param := field.Param()
	var id uint
	if param == "update" {
		i := field.Parent().Interface()
		request := i.(requrest.ArticleCateUpdateRequest)
		id = request.Id
	}
	if articleCategoryModel.CheckNameExist(username, id) {
		return false
	}
	return true
}
